﻿using System;
using System.Collections.Generic;
using System.Linq;
using Manager;
using UnityEngine;

namespace Studio
{
	// Token: 0x02000463 RID: 1123
	public static class AddObjectFemale
	{
		// Token: 0x06001C14 RID: 7188 RVA: 0x000B4DE0 File Offset: 0x000B2FE0
		public static OCICharFemale Add(string _path)
		{
			//ChaControl chaControl = Singleton<Character>.CreateFemale(Singleton<Scene>.Instance.commonSpace, -1, null, null);
			//chaControl.human.customParam.Load(_path, true, false);
			//OICharInfo oicharInfo = new OICharInfo(chaControl.human.customParam, Studio.GetNewIndex());
			//CharaInfo charaInfo = new CharaInfo();
			//charaInfo.Load(_path);
			//oicharInfo.fileStatus.name = charaInfo.name;
			//return AddObjectFemale.Add(chaControl, oicharInfo, null, null, true, Studio.optionSystem.initialPosition);
			return null;
		}

		// Token: 0x06001C15 RID: 7189 RVA: 0x000B4E60 File Offset: 0x000B3060
		public static OCICharFemale Load(OICharInfo _info, ObjectCtrlInfo _parent, TreeNodeObject _parentNode)
		{
			//ChaControl chaControl = Singleton<Character>.Instance.CreateFemale(Singleton<Scene>.Instance.commonSpace, -1, _info.charFile, _info.fileStatus);
			//_info.charFile = chaControl.human.customParam;
			//OCICharFemale ocicharFemale = AddObjectFemale.Add(chaControl, _info, _parent, _parentNode, false, -1);
			//using (Dictionary<int, List<ObjectInfo>>.Enumerator enumerator = _info.child.GetEnumerator())
			//{
			//	while (enumerator.MoveNext())
			//	{
			//		KeyValuePair<int, List<ObjectInfo>> v = enumerator.Current;
			//		AddObjectAssist.LoadChild(v.Value, ocicharFemale, ocicharFemale.dicAccessoryPoint.First((KeyValuePair<TreeNodeObject, int> x) => x.Value == v.Key).Key);
			//	}
			//}
			//return ocicharFemale;
			return null;
		}

		// Token: 0x06001C16 RID: 7190 RVA: 0x000B4F34 File Offset: 0x000B3134
		private static OCICharFemale Add(ChaControl _female, OICharInfo _info, ObjectCtrlInfo _parent, TreeNodeObject _parentNode, bool _addInfo, int _initialPosition)
		{
			OCICharFemale ocicharFemale = new OCICharFemale();
			_female.Load(_info.charFile);
			_female.InitializeExpression(true);
			ocicharFemale.charInfo = _female;
			ocicharFemale.fullBodyIK = _female.human.ik.FBIK;
			ocicharFemale.objectInfo = _info;
			string name = (!_addInfo) ? string.Empty : _info.fileStatus.name;
			_info.fileStatus = ocicharFemale.charStatus;
			if (_addInfo)
			{
				_info.fileStatus.name = name;
			}
			GuideObject guideObject = Singleton<GuideObjectManager>.Instance.Add(_female.transform, _info.dicKey);
			guideObject.scaleSelect = 0.1f;
			guideObject.scaleRot = 0.05f;
			GuideObject guideObject2 = guideObject;
			guideObject2.isActiveFunc = (GuideObject.IsActiveFunc)Delegate.Combine(guideObject2.isActiveFunc, new GuideObject.IsActiveFunc(ocicharFemale.OnSelect));
			ocicharFemale.guideObject = guideObject;
			ocicharFemale.optionItemCtrl = _female.gameObject.AddComponent<OptionItemCtrl>();
			ocicharFemale.optionItemCtrl.animator = _female.animBody;
			ocicharFemale.optionItemCtrl.oiCharInfo = _info;
			ChangeAmount changeAmount = _info.changeAmount;
			changeAmount.onChangeScale = (Action<Vector3>)Delegate.Combine(changeAmount.onChangeScale, new Action<Vector3>(ocicharFemale.optionItemCtrl.ChangeScale));
			ocicharFemale.charAnimeCtrl = _female.gameObject.AddComponent<CharAnimeCtrl>();
			ocicharFemale.charAnimeCtrl.animator = _female.animBody;
			ocicharFemale.charAnimeCtrl.oiCharInfo = _info;
			AddObjectAssist.InitHandAnime(ocicharFemale);
			if (_info.animeInfo.group == 0 && _info.animeInfo.category == 0 && _info.animeInfo.no == 0)
			{
				int group = _info.animeInfo.group;
				int category = _info.animeInfo.category;
				int no = _info.animeInfo.no;
				float animeNormalizedTime = _info.animeNormalizedTime;
				ocicharFemale.LoadAnime(0, 1, 0, 0f);
				_female.animBody.Update(0f);
				_info.animeInfo.group = group;
				_info.animeInfo.category = category;
				_info.animeInfo.no = no;
				_info.animeNormalizedTime = animeNormalizedTime;
			}
			if (_addInfo)
			{
				Studio.AddInfo(_info, ocicharFemale);
			}
			else
			{
				Studio.AddObjectCtrlInfo(ocicharFemale);
			}
			TreeNodeObject treeNodeObject = Studio.AddNode(_female.fileStatus.name, null);
			treeNodeObject.enableChangeParent = false;
			treeNodeObject.treeState = _info.treeState;
			TreeNodeObject treeNodeObject2 = treeNodeObject;
			treeNodeObject2.onVisible = (TreeNodeObject.OnVisibleFunc)Delegate.Combine(treeNodeObject2.onVisible, new TreeNodeObject.OnVisibleFunc(ocicharFemale.OnVisible));
			treeNodeObject.enableVisible = true;
			treeNodeObject.visible = _info.visible;
			guideObject.guideSelect.treeNodeObject = treeNodeObject;
			ocicharFemale.treeNodeObject = treeNodeObject;
			_info.changeAmount.OnChange();
			AddObjectAssist.InitBone(ocicharFemale, _female.objBodyBone.transform, Singleton<Info>.Instance.dicFemaleBoneInfo);
			AddObjectAssist.InitIKTarget(ocicharFemale, _addInfo);
			AddObjectAssist.InitLookAt(ocicharFemale);
			AddObjectAssist.InitAccessoryPoint(ocicharFemale);
			ocicharFemale.voiceCtrl.ociChar = ocicharFemale;
			ocicharFemale.InitKinematic(_female.gameObject, ocicharFemale.fullBodyIK, _female.neckLookCtrl, AddObjectFemale.GetHairDynamic(_female), AddObjectFemale.GetSkirtDynamic(_female));
			treeNodeObject.enableAddChild = false;
			Studio.AddCtrlInfo(ocicharFemale);
			if (_parent != null)
			{
				_parent.OnLoadAttach((!(_parentNode != null)) ? _parent.treeNodeObject : _parentNode, ocicharFemale);
			}
			if (_initialPosition == 1)
			{
				_info.changeAmount.pos = Singleton<Studio>.Instance.cameraCtrl.targetPos;
			}
			ocicharFemale.LoadAnime(_info.animeInfo.group, _info.animeInfo.category, _info.animeInfo.no, _info.animeNormalizedTime);
			for (int l = 0; l < 5; l++)
			{
				ocicharFemale.ActiveIK((OIBoneInfo.BoneGroup)(1 << l), _info.activeIK[l], false);
			}
			ocicharFemale.ActiveKinematicMode(OICharInfo.KinematicMode.IK, _info.enableIK, true);
			foreach (var callback in FKCtrl.parts.Select((OIBoneInfo.BoneGroup p, int i) => new
			{
				p,
				i
			}))
			{
				ocicharFemale.ActiveFK(callback.p, ocicharFemale.oiCharInfo.activeFK[callback.i], ocicharFemale.oiCharInfo.activeFK[callback.i]);
			}
			ocicharFemale.ActiveKinematicMode(OICharInfo.KinematicMode.FK, _info.enableFK, true);
			for (int j = 0; j < _info.expression.Length; j++)
			{
				ocicharFemale.charInfo.EnableExpressionCategory(j, _info.expression[j]);
			}
			ocicharFemale.animeSpeed = ocicharFemale.animeSpeed;
			CharFileStatus fileStatus = _female.fileStatus;
			byte[] siruLv = fileStatus.siruLv;
			for (int k = 0; k < siruLv.Length; k++)
			{
				siruLv[k] = 0;
			}
			AddObjectAssist.UpdateState(ocicharFemale);
			if (!_info.visible)
			{
				ocicharFemale.female.human.SetVisibleAll(true);
				ocicharFemale.female.human.SetVisibleAll(false);
			}
			return ocicharFemale;
		}

		// Token: 0x06001C17 RID: 7191 RVA: 0x000B5460 File Offset: 0x000B3660
		public static DynamicBone[] GetHairDynamic(ChaControl _female)
		{
			if (_female == null)
			{
				return null;
			}
			return _female.human.hairs.dynamicBone;
		}

		// Token: 0x06001C18 RID: 7192 RVA: 0x000B547C File Offset: 0x000B367C
		public static DynamicBone[] GetSkirtDynamic(ChaControl _female)
		{
			if (_female == null)
			{
				return null;
			}
			string[] target = (from v in Singleton<Info>.Instance.dicFemaleBoneInfo
			where v.Value.@group == 13
			select v.Value.bone).ToArray<string>();
			List<DynamicBone> list = new List<DynamicBone>();
			int[] array = new int[]
			{
				0,
				1,
				5,
				6
			};
			for (int i = 0; i < array.Length; i++)
			{
				DynamicBone[] skirtDynamic = AddObjectFemale.GetSkirtDynamic(_female.human.wears.objWear[array[i]], target);
				if (!skirtDynamic.IsNullOrEmpty<DynamicBone>())
				{
					list.AddRange(skirtDynamic);
				}
			}
			return list.ToArray();
		}

		// Token: 0x06001C19 RID: 7193 RVA: 0x000B554C File Offset: 0x000B374C
		private static DynamicBone[] GetSkirtDynamic(GameObject _object, string[] _target)
		{
			if (_object == null)
			{
				return null;
			}
			DynamicBone[] componentsInChildren = _object.GetComponentsInChildren<DynamicBone>();
			return (from v in componentsInChildren
			where v.m_Root != null && _target.Any((string s) => s == v.m_Root.name)
			select v).ToArray<DynamicBone>();
		}
	}
}
